package com.daluzy.chmanager.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.daluzy.chmanager.MyApplication;
import com.daluzy.chmanager.R;
import com.daluzy.chmanager.activity.AddManagerActivity;
import com.daluzy.chmanager.activity.AreaManageActivity;
import com.daluzy.chmanager.activity.CommentManageActivity;
import com.daluzy.chmanager.activity.EmployeeInfoActivity;
import com.daluzy.chmanager.activity.EmployeeManageActivity;
import com.daluzy.chmanager.activity.FeedbackManageActivity;
import com.daluzy.chmanager.activity.ManageManagerActivity;
import com.daluzy.chmanager.activity.MyCommentActivity;
import com.daluzy.chmanager.activity.MyRecordActivity;
import com.daluzy.chmanager.activity.SchoolManageActivity;
import com.daluzy.chmanager.activity.ServiceManageActivity;
import com.daluzy.chmanager.activity.StudentInfoActivity;
import com.daluzy.chmanager.activity.StudentManageActivity;
import com.daluzy.chmanager.activity.TestPointManageActivity;
import com.daluzy.chmanager.activity.UserInfoActivity;
import com.daluzy.chmanager.bean.Employee;
import com.daluzy.chmanager.bean.Manager;
import com.daluzy.chmanager.bean.Students;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bmob.v3.util.V;

public class MineFragment extends Fragment {

    @BindView(R.id.rl_user_info)
    RelativeLayout rlUserInfo;
    @BindView(R.id.rl_my_record)
    RelativeLayout rlMyRecord;
    @BindView(R.id.rl_my_comment)
    RelativeLayout rlMyComment;
    @BindView(R.id.rl_comment_manager)
    RelativeLayout rlCommentManager;
    @BindView(R.id.rl_student_manager)
    RelativeLayout rlStudentManager;
    @BindView(R.id.rl_employee_manager)
    RelativeLayout rlEmployeeManager;
    @BindView(R.id.rl_school_manager)
    RelativeLayout rlSchoolManager;
    @BindView(R.id.rl_service_manager)
    RelativeLayout rlServiceManager;
    @BindView(R.id.rl_feedback_manager)
    RelativeLayout rlFeedbackManager;
    @BindView(R.id.rl_area_manager)
    RelativeLayout rlAreaManager;
    @BindView(R.id.rl_test_point_manager)
    RelativeLayout rlTestPointManager;
    @BindView(R.id.tv_user_name)
    TextView tvUserName;
    @BindView(R.id.rl_add_manager)
    RelativeLayout rlAddManager;
    private Context context;

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        this.context = getActivity();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_mine_daluzy, container, false);
        ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        int type = MyApplication.getIntance().getUserType();
        if (type == 1) {
            Students students = MyApplication.getIntance().getStudents();
            setStudent(students);
        } else if (type == 2) {
            Employee employee = MyApplication.getIntance().getEmployee();
            setEmployee(employee);
        } else if (type == 3) {
            Manager manager = MyApplication.getIntance().getManager();
            setManager(manager);
        }
    }

    @OnClick({R.id.rl_user_info, R.id.rl_my_record, R.id.rl_my_comment, R.id.rl_comment_manager
            , R.id.rl_student_manager, R.id.rl_employee_manager, R.id.rl_school_manager, R.id.rl_service_manager
            , R.id.rl_feedback_manager, R.id.rl_area_manager, R.id.rl_test_point_manager, R.id.rl_add_manager})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.rl_user_info://基本信息
                if (MyApplication.getIntance().getUserType() == 1) {
                    Intent intent = new Intent(context, StudentInfoActivity.class);
                    intent.putExtra("studentId", MyApplication.getIntance().getStudents().getObjectId());
                    context.startActivity(intent);
                } else {
                    context.startActivity(new Intent(context, EmployeeInfoActivity.class));
                }
                break;
            case R.id.rl_my_record://我的反馈
                context.startActivity(new Intent(context, MyRecordActivity.class));
                break;
            case R.id.rl_my_comment://我的评论
                context.startActivity(new Intent(context, MyCommentActivity.class));
                break;
            case R.id.rl_comment_manager://管理员评论管理
                context.startActivity(new Intent(context, CommentManageActivity.class));
                break;
            case R.id.rl_student_manager://学生管理
                context.startActivity(new Intent(context, StudentManageActivity.class));
                break;
            case R.id.rl_employee_manager://后勤人员管理
                context.startActivity(new Intent(context, EmployeeManageActivity.class));
                break;
            case R.id.rl_school_manager://学校管理
                context.startActivity(new Intent(context, SchoolManageActivity.class));
                break;
            case R.id.rl_service_manager://后勤人员我的维修
                context.startActivity(new Intent(context, ServiceManageActivity.class));
                break;
            case R.id.rl_feedback_manager://后勤人员我的反馈
                context.startActivity(new Intent(context, FeedbackManageActivity.class));
                break;
            case R.id.rl_area_manager://区域管理
                context.startActivity(new Intent(context, AreaManageActivity.class));
                break;
            case R.id.rl_test_point_manager://测试点管理
                context.startActivity(new Intent(context, TestPointManageActivity.class));
                break;
            case R.id.rl_add_manager://添加管理员
                context.startActivity(new Intent(context, ManageManagerActivity.class));
                break;
        }
    }

    /**
     * 学生
     *
     * @param student
     */
    private void setStudent(Students student) {
        rlUserInfo.setVisibility(View.VISIBLE);
        rlMyRecord.setVisibility(View.VISIBLE);
        rlMyComment.setVisibility(View.VISIBLE);
        rlCommentManager.setVisibility(View.GONE);
        rlStudentManager.setVisibility(View.GONE);
        rlEmployeeManager.setVisibility(View.GONE);
        rlSchoolManager.setVisibility(View.GONE);
        rlServiceManager.setVisibility(View.GONE);
        rlFeedbackManager.setVisibility(View.GONE);
        rlAreaManager.setVisibility(View.GONE);
        rlTestPointManager.setVisibility(View.GONE);
        rlAddManager.setVisibility(View.GONE);
        tvUserName.setText(student.getStudent_name());
    }

    private void setEmployee(Employee employee) {
        rlUserInfo.setVisibility(View.VISIBLE);
        rlMyRecord.setVisibility(View.GONE);
        rlMyComment.setVisibility(View.GONE);
        rlCommentManager.setVisibility(View.GONE);
        rlStudentManager.setVisibility(View.GONE);
        rlEmployeeManager.setVisibility(View.GONE);
        rlSchoolManager.setVisibility(View.GONE);
        rlServiceManager.setVisibility(View.VISIBLE);
        rlFeedbackManager.setVisibility(View.VISIBLE);
        rlAreaManager.setVisibility(View.VISIBLE);
        rlTestPointManager.setVisibility(View.VISIBLE);
        rlAddManager.setVisibility(View.GONE);
        tvUserName.setText(employee.getEmployee_name());
    }

    private void setManager(Manager manager) {
        rlUserInfo.setVisibility(View.VISIBLE);
        rlMyRecord.setVisibility(View.GONE);
        rlMyComment.setVisibility(View.GONE);
        rlCommentManager.setVisibility(View.VISIBLE);
        rlStudentManager.setVisibility(View.VISIBLE);
        rlEmployeeManager.setVisibility(View.VISIBLE);
        rlSchoolManager.setVisibility(View.VISIBLE);
        rlServiceManager.setVisibility(View.GONE);
        rlFeedbackManager.setVisibility(View.GONE);
        rlAreaManager.setVisibility(View.VISIBLE);
        rlTestPointManager.setVisibility(View.VISIBLE);
        rlAddManager.setVisibility(View.VISIBLE);
        tvUserName.setText(manager.getManager_name());
    }

    @Override
    public void onResume() {
        super.onResume();
        initView();
    }
}
